/**
 * Created by user on 2015/9/21.
 */

var cardService = require('../../../services/mis/operate/cardService');
var messageUtil = require('../../../common/utils/messageUtil');
var toolUtil = require('../../../common/utils/toolUtil');

exports.cardList = function(req, res) {

    cardService.cardListService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when cardList...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when cardList...'));
        }else {
            var data = {
                count:results[0]["count"],
                totalPage: results[0]["totalPage"],
                list: results[1]
            };
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });

};

exports.cardAdd = function (req, res) {

    cardService.cardAddService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when addPrize ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};


exports.cardDelete = function (req, res) {

    cardService.cardDeleteService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when addPrize ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};


exports.cardEdit = function (req, res) {

    cardService.cardEditService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when editCard ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};

exports.cardPush = function (req, res){

    cardService.cardPushService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when cardPush ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });

};